package tests;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import lib.Utility;
import lib.logging.ANSIConsoleLogger;
import lib.logging.ILogger;
import lib.messaging.Communicator;
import lib.messaging.IReceiver;

/**
 * A test receiver using IReceiver to receive commands
 *
 * @author abhip
 *
 */
public class TestReceiverProgram
{
    public static void main(String args[])
    {
        final int ReceiverPort = 2012;
        final double PacketDropProbability = 0.0f;

        ILogger logger = new ANSIConsoleLogger();

        try {
            IReceiver server = new Communicator(PacketDropProbability, logger);
            logger.LogInfo("Waiting for connection...");

            byte[] bytes = server.ReceiveBytes(ReceiverPort);
            String data;

            data = Utility.ByteArrayToString(bytes);
            logger.LogInfo("Received: " + data);
        } catch (UnsupportedEncodingException e) {
            logger.LogException(e);
        } catch (IOException e) {
            logger.LogException(e);
        } catch (ClassNotFoundException e) {
            logger.LogException(e);
        }
    }
}
